<%@ page import="com.macrosolution.exdebito.Perito" %>

<html>
	<head>
		<meta name="layout" content="kickstart"/>
		<title>Mr-Rights|Lista Periti</title>
	</head>
<body>
<!-- RIBBON-->
<div id="ribbon">
	<div class="col-lg-5">
		<ol class="breadcrumb">
			<li>Periti</li><li>lista</li>
		</ol>
	</div>
	<div class="col-lg-7" align="right" style="margin-top:4px;">
		<input type="button" class="btn btn-info btn-sm col-md-offset-3" name="add_perito" value="&nbsp;&nbsp;Aggiungi Perito" 
				onClick="location.href='${createLink(controller:'perito',action:'create') }'" class="fa fa-plus-circle">
	</div>
</div>
<!-- END RIBBON -->

<script type="text/javascript">

</script>	
<!-- MAIN CONTENT -->
<div id="content">
<div class="row">
	<div class="col-lg-12">
		<div class="jarviswidget jarviswidget-color-darken" id="wid-id-0" data-widget-editbutton="false">
			<div>
				<!-- widget edit box -->
				<div class="jarviswidget-editbox">
					<!-- This area used as dropdown edit box -->
				</div>
				<!-- end widget edit box -->
				
				<!-- widget content -->
				<div class="widget-body no-padding">
					<table id="dt_basic" class="table table-striped table-bordered table-hover" width="100%">
						<thead>			                
							<tr>
								<th >Perito</th>
								<th >Tel.</th>
								<th >Mail</th>
								<th >Provncia</th>
								<th></th>								
							</tr>
						</thead>
						<tbody>
						<g:each  in="${periti}" var="perito">						
							<tr>
								<td><a href="${createLink(controller:'perito',action:'show',id:perito?.id)}" >${(perito?.surname) ? (perito?.surname).toUpperCase() : (perito?.surname)}&nbsp;&nbsp;${(perito?.name) ? (perito?.name).toUpperCase() : (perito?.name) }</a></td>
								<td>${perito?.mobile}</td>
								<td>${perito?.company_email}</td>
								<td>${perito?.fiscalAddress?.province?.nome}</td>
			<sec:ifAnyGranted roles="ROLE_ADMIN,ROLE_AMM">
								<td align="center"><exdutility:btn_manage cancel-function="cancelPerito(${perito?.id})" id="${perito?.id}" controller="perito" action="edit" /></td>
			</sec:ifAnyGranted>					
							</tr>	
						</g:each>
						</tbody>
					</table>
				</div>
				<!-- end widget content -->
			</div>
			<!-- end widget div -->
		</div>				
	</div>
</div>
</div>
<script src="${resource(dir: 'site/js/plugin/datatables', file: 'jquery.dataTables.min.js')}"></script>
<script src="${resource(dir: 'site/js/plugin/datatables', file: 'dataTables.colVis.min.js')}"></script>			
<script src="${resource(dir: 'site/js/plugin/datatables', file: 'dataTables.tableTools.min.js')}"></script>
<script src="${resource(dir: 'site/js/plugin/datatables', file: 'dataTables.bootstrap.min.js')}"></script>
<script src="${resource(dir: 'site/js/plugin/datatable-responsive', file: 'datatables.responsive.min.js')}"></script>

<script type="text/javascript">
		$(document).ready(function() {
			pageSetUp();
			buildTable();
		});

		function cancelPerito(id_perito){
				$.SmartMessageBox({
					title : "<div class='row'><div class='col-md-2'><i class='fa '></i></div><div class='col-md-10'>Stai per eliminare un perito dalla piattaforma!</div>",
					content : "<div class='col-md-2'></div><div class='col-md-10'> Sei sicuro di volerlo fare?<BR/><BR/></div></div>",
					buttons:"[Si],[No]",
					sound:false
				}, function(ButtonPressed, Value) {
					if (ButtonPressed === "No") {						
					}
					if (ButtonPressed === "Si") {
						${remoteFunction(asynchronous: true,
			 					action:'delete',
								controller:'perito',
								params:'\'id=\'+id_perito',
								onSuccess:'showCancelResponse(data)'
								)} 
					}
				   });
		}
		
		function showCancelResponse(data){
			$.smallBox({
				title : data.message,
				color : "#3F8DBF",
				sound:false,
				timeout: 3000
			});
			setTimeout(function(){ location.reload();}, 2000);			
		}
			
		function buildTable(){
			/* BASIC ;*/
			var responsiveHelper_dt_basic = undefined;
			var responsiveHelper_datatable_fixed_column = undefined;
			var responsiveHelper_datatable_col_reorder = undefined;
			var responsiveHelper_datatable_tabletools = undefined;
			
			var breakpointDefinition = {
				tablet : 1024,
				phone : 480
			};
			$('#dt_basic').dataTable({
				"sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-12 hidden-xs'l>r>"+"t"+
					"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
				"autoWidth" : true,
				"preDrawCallback" : function() {
					// Initialize the responsive datatables helper once.
					if (!responsiveHelper_dt_basic) {
						responsiveHelper_dt_basic = new ResponsiveDatatablesHelper($('#dt_basic'), breakpointDefinition);
					}
				},
				"rowCallback" : function(nRow) {
					responsiveHelper_dt_basic.createExpandIcon(nRow);
				},
				"drawCallback" : function(oSettings) {
					responsiveHelper_dt_basic.respond();
				}
			});
		/* END BASIC */
		
		/* COLUMN FILTER  */
	    var otable = $('#datatable_fixed_column').DataTable({
	    	//"bFilter": false,
	    	//"bInfo": false,
	    	//"bLengthChange": false
	    	//"bAutoWidth": false,
	    	//"bPaginate": false,
	    	//"bStateSave": true // saves sort state using localStorage
			"sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6 hidden-xs'f><'col-sm-6 col-xs-12 hidden-xs'<'toolbar'>>r>"+"t"+
					"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
			"autoWidth" : true,
			"preDrawCallback" : function() {
				// Initialize the responsive datatables helper once.
				if (!responsiveHelper_datatable_fixed_column) {
					responsiveHelper_datatable_fixed_column = new ResponsiveDatatablesHelper($('#datatable_fixed_column'), breakpointDefinition);
				}
			},
			"rowCallback" : function(nRow) {
				responsiveHelper_datatable_fixed_column.createExpandIcon(nRow);
			},
			"drawCallback" : function(oSettings) {
				responsiveHelper_datatable_fixed_column.respond();
			}				
	    });	    
	    // custom toolbar
	    $("div.toolbar").html('<div class="text-right"><img src="img/logo.png" alt="SmartAdmin" style="width: 111px; margin-top: 3px; margin-right: 10px;"></div>');	    	   
	    // Apply the filter
	    $("#datatable_fixed_column thead th input[type=text]").on( 'keyup change', function () {    	
	        otable
	            .column( $(this).parent().index()+':visible' )
	            .search( this.value )
	            .draw();	            
	    } );
	    /* END COLUMN FILTER */   

		/* COLUMN SHOW - HIDE */
		$('#datatable_col_reorder').dataTable({
			"sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-6 hidden-xs'C>r>"+"t"+
					"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-sm-6 col-xs-12'p>>",
			"autoWidth" : true,
			"preDrawCallback" : function() {
				// Initialize the responsive datatables helper once.
				if (!responsiveHelper_datatable_col_reorder) {
					responsiveHelper_datatable_col_reorder = new ResponsiveDatatablesHelper($('#datatable_col_reorder'), breakpointDefinition);
				}
			},
			"rowCallback" : function(nRow) {
				responsiveHelper_datatable_col_reorder.createExpandIcon(nRow);
			},
			"drawCallback" : function(oSettings) {
				responsiveHelper_datatable_col_reorder.respond();
			}			
		});		
		/* END COLUMN SHOW - HIDE */

		/* TABLETOOLS */
		$('#datatable_tabletools').dataTable({			
			// Tabletools options: 
			//   https://datatables.net/extensions/tabletools/button_options
			"sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-6 hidden-xs'T>r>"+"t"+
					"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-sm-6 col-xs-12'p>>",
	        "oTableTools": {
	        	 "aButtons": [
	             "copy",
	             "csv",
	             "xls",
	                {
	                    "sExtends": "pdf",
	                    "sTitle": "SmartAdmin_PDF",
	                    "sPdfMessage": "SmartAdmin PDF Export",
	                    "sPdfSize": "letter"
	                },
	             	{
	                	"sExtends": "print",
	                	"sMessage": "Generated by SmartAdmin <i>(press Esc to close)</i>"
	            	}
	             ],
	            "sSwfPath": "js/plugin/datatables/swf/copy_csv_xls_pdf.swf"
	        },
			"autoWidth" : true,
			"preDrawCallback" : function() {
				// Initialize the responsive datatables helper once.
				if (!responsiveHelper_datatable_tabletools) {
					responsiveHelper_datatable_tabletools = new ResponsiveDatatablesHelper($('#datatable_tabletools'), breakpointDefinition);
				}
			},
			"rowCallback" : function(nRow) {
				responsiveHelper_datatable_tabletools.createExpandIcon(nRow);
			},
			"drawCallback" : function(oSettings) {
				responsiveHelper_datatable_tabletools.respond();
			}
		});
		
			}
</script>			
</body>

</HTML>			